package com.pms.mapper;

import com.github.pagehelper.Page;
import com.pms.dto.CommunityPageQueryDTO;
import com.pms.entity.Community;
import com.pms.vo.CommunityPageQueryVO;
import com.pms.vo.CommunitySelectVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommunityMapper {
    /**
     * 根据社区名查询社区
     * @param name
     * @return
     */
    @Select("select * from community where name = #{name}")
    Community getByName(String name);

    /**
     * 插入社区信息
     * @param community
     */
    void insert(Community community);

    /**
     * 分页查询
     * @param communityPageQueryDTO
     * @return
     */
    Page<CommunityPageQueryVO> pageQuery(CommunityPageQueryDTO communityPageQueryDTO);

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from community where id=#{id}")
    void delete(Integer id);

    /**
     * 修改社区信息
     * @param community
     */
    @Update("update community " +
            "set name=#{name},address=#{address},manager=#{manager},phone=#{phone} where id=#{id}")
    void update(Community community);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from community where id=#{id}")
    Community getById(Integer id);

    /**
     * 小区列表
     * @return
     */
    @Select("select id, name from community")
    List<CommunitySelectVO> list();

    /**
     * 统计总数
     * @return
     */
    @Select("select count(*) from community")
    Integer count();

}
